package com.example.newheze.Camera;

import android.app.Fragment;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.VideoView;

import com.bumptech.glide.Glide;
import com.example.newheze.R;

import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

public class CameraActivity extends Fragment {

    private View view;

    private JzvdStd jzvdStd1;
    private JzvdStd jzvdStd2;
    private JzvdStd jzvdStd3;
    private JzvdStd jzvdStd4;

    private VideoView videoView;
    private Button button;
    private Button button_2;
    private Spinner spinner1;
    private String strPath=null;
    private int intSpinnerFlag=0;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.camera, container, false);
        jzvdStd1=view.findViewById(R.id.videoview_1);
        jzvdStd2=view.findViewById(R.id.videoview_2);
        jzvdStd3=view.findViewById(R.id.videoview_3);
        jzvdStd4=view.findViewById(R.id.videoview_4);
        JzvdStd.SAVE_PROGRESS=false;
        jzvdStd1.setUp("http://alhlsgw.lechange.com:9001/LCO/4J0059DAAJC2663/0/0/20181220211617/dev_20181220211617_tlxtkxkfqnlfb3a4.m3u8",  "9号棚",Jzvd.SCREEN_WINDOW_NORMAL);
        jzvdStd2.setUp("http://alhlsgw.lechange.com:9001/LCO/4J0059DAAJD821A/0/0/20181220212156/dev_20181220212156_d6lqq6ntbamkxbqp.m3u8",  "10号棚",Jzvd.SCREEN_WINDOW_NORMAL);
        jzvdStd3.setUp("http://paasalihlsgw.lechange.cn:9001/LCO/4H0736APAN46EE0/0/0/20181220184328/dev_20181220184328_5312i12x1xs0chf2.m3u8",  "正门",Jzvd.SCREEN_WINDOW_NORMAL);
        jzvdStd4.setUp("http://alhlsgw.lechange.com:9001/LCO/3L061C0PAJ00344/0/0/20181220184438/dev_20181220184438_d8iasm81q6b609c8.m3u8",  "8号棚",Jzvd.SCREEN_WINDOW_NORMAL);
        jzvdStd1.thumbImageView.setImageResource(R.drawable.video_face_1);
        jzvdStd2.thumbImageView.setImageResource(R.drawable.video_face_2);
        jzvdStd3.thumbImageView.setImageResource(R.drawable.video_face_3);
        jzvdStd4.thumbImageView.setImageResource(R.drawable.video_face_4);


        /*buttonOperate();
        startOperate();
        adaqptSpinner();
        monitorSelect();
        videoView=view.findViewById(R.id.videoview_1);
        videoView.setVideoPath("http://alhlsgw.lechange.com:9001/LCO/4J0059DAAJC2663/0/0/20181220211617/dev_20181220211617_tlxtkxkfqnlfb3a4.m3u8");
        getDraw();*/
        return view;
    }

    /*public void getDraw()
    {
        Resources resources=getResources();
        //videoView.setBackground(resources.getDrawable(R.drawable.video_face));
    }

    public void buttonOperate()
    {
        button=view.findViewById(R.id.video_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                videoView.pause();
            }
        });
    }

    public void startOperate()
    {
        button_2=view.findViewById(R.id.video_button_2);
        button_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                videoView.start();
                videoView.setBackground(null);
            }
        });
    }

    public void adaqptSpinner()
    {
        String monitorName[]=getMonitor();
        spinner1=view.findViewById(R.id.spinner_1);
        ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1,monitorName);
        spinner1.setAdapter(arrayAdapter);
    }

    public String[] getMonitor()
    {
        Resources resources;
        resources=getResources();
        String string[]=resources.getStringArray(R.array.play_back_speed);
        return string;
    }

    public void monitorSelect()
    {
        Resources resources=getResources();
        final String strAddress[]=resources.getStringArray(R.array.address);
        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if(intSpinnerFlag!=0)
                {
                    Toast.makeText(getActivity(),"监控"+(position+1)+",加载时间较长，请耐心等待",Toast.LENGTH_LONG).show();
                    videoView.pause();
                    videoView.setVideoPath(strAddress[position]);
                    videoView.start();
                }
                else
                    intSpinnerFlag++;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                Toast.makeText(getActivity(),"nothing",Toast.LENGTH_SHORT).show();
            }
        });
    }*/





}
